﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalDetection
{
   public class FormFactory
    {
        private static FrmDetectionInterface frmDetectionInterface;
        private static FrmConfiguration frmConfiguration;
        private static Form form;
        private static List<Form> forms = new List<Form>();

        /// <summary>
        /// 工厂模式--创建窗体
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static Form CreateForm(int index)
        {
            HideFormAll();
            switch (index)
            {
                case 0:
                    frmDetectionInterface = new FrmDetectionInterface();
                    forms.Add(frmDetectionInterface);
                    form = frmDetectionInterface;
                    break;
                case 1:
                    frmConfiguration = new FrmConfiguration();
                    forms.Add(frmConfiguration);
                    form = frmConfiguration;
                    break;
                default:
                    MessageBox.Show("无窗体创建");
                    break;
            }

            return form;
        }
        /// <summary>
        /// 清除所有组件
        /// </summary>
        private static void HideFormAll()
        {
            foreach (Form form in forms)
            {
                form.Hide();
            }
        }
    }
}
